package com.wangjiang.foundation.exception.handler;

import com.wangjiang.foundation.exception.exceptions.NoFoundException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController {

    @RequestMapping("/error")
    public void handleError(HttpServletRequest request) throws Throwable {
        if (request.getAttribute("javax.servlet.error.exception") != null) {
            throw (Throwable) request.getAttribute("javax.servlet.error.exception");
        } else {
            throw new NoFoundException("路径不存在");
        }
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
